package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo5 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> cls=Class.forName("reflect.Person");//获取类对象
        Constructor<?>constructor=cls.getConstructor(String.class);
        Person obj=(Person)constructor.newInstance("小刘");
        Method method=cls.getMethod("say",String.class,int.class);
        method.invoke(obj,"干嘛呢",5);


    }
}
